import React, { useMemo } from 'react'
import { Redirect, Switch, Route } from 'react-router-dom'//BrowserRouter模式，路径
import routers from '../../router';
interface WithRouterViewProps {
  path: string;
  level?: number;
}
export default function WithRouterView(props: WithRouterViewProps) {
  const { path, level } = props;
  console.log('level', level);
  const sonRouter = useMemo(() => {
    return routers.filter((item) => item.path === path)
  }, [path]);

  return (
    <Switch>
      {
        Array.isArray(sonRouter[0]?.children) && sonRouter[0]?.children.map((item) => {
          switch (item.path) {
            case path:
              {
                return item.redirect && <Redirect key={item.key} to={item.to} exact={item.exact ? true : false} />
              }
            default: {
              return <Route key={item.key} path={item.path} component={item.component} exact={item.exact ? true : false} />
            }
          }
        })
      }
    </Switch>
  )
}
